chrome.extension.onRequest.addListener(onRequest);

function onRequest(request, sender, sendResponse) {
    if (request.type == "sharePage") {
        console.log(request.data);
        showModal(request.data);
        console.log('modal');
    }

    sendResponse();
}

function showModal(data) {
    var html = [];
    //html.push('<div class="modal-backdrop fade in"></div>');
    html.push('<div id="tsModal" class="modal hide fade">');
    html.push('<div class="modal-header" style="text-align:left;">');
    html.push('<a href="#" class="close" style="text-decoration:none">&times;</a>');
    html.push('<h3>分享到微博</h3>');
    html.push('</div>');
    html.push('<div class="modal-body">');
    html.push('<p><textarea id="" rows="5" cols="103">');
    html.push(data.title);
    html.push(' ');
    html.push(data.url);
    html.push('</textarea></p>');
    html.push('</div>');
    html.push('<div class="modal-footer">');
    html.push('<a href="#" class="btn primary" style="text-decoration:none">发送微博</a>');
    html.push('<a href="#" class="btn secondary" style="text-decoration:none">取消发送</a>');
    html.push('</div>');
    html.push('</div>');

    $(document.body).append(html.join(''));
    $('#tsModal').modal({backdrop:true,keyboard:true});
}

(function() {
/*
    var modal = document.createElement("script");
    modal.src = "http://twitter.github.com/bootstrap/1.4.0/bootstrap-modal.js";
    var jq = document.createElement("script");
    jq.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js";
    document.getElementsByTagName('head')[0].appendChild(jq);
    document.getElementsByTagName('head')[0].appendChild(modal);
*/
})();